<?php
/**
*	@author SignpostMarv Martin
*	@package LLSD
*/

/**
*	The class used to represent date LLSD nodes- allows a native PHP data type to hold date elements in order to differentiate them from normal strings
*	@package LLSD
*/
class uhu_LLSD_date extends uhu_LLSD_common
{
/**
*	@var string The contents of the date element
*/
	protected $date;
/**
*	@var integer A UNIX timestamp of {@link uhu_LLSD_date::$date}
*/
	protected $unix;
/**
*	Bulds an isntance of uhu_LLSD_date
*	@param string|SimpleXMLElement A string or date element to use as 
*	@uses uhu_LLSD_exception
*/
	public function __construct($date)
	{
		if($date instanceof SimpleXMLElement)
		{
			$date = (string)$date;
		}
		if(is_string($date) === false)
		{
			throw new uhu_LLSD_exception('Date not provided as string.',105);
		}
		else if(($this->unix = strtotime($date)) === false)
		{
			throw new uhu_LLSD_exception('Value provided not valid date format.',105);
		}
		else
		{
			$this->date = $date;
		}
	}
/**
*	@return integer the UNIX timestamp for the date supplied in uhu_LLSD_date::__construct()
*/
	public function unix()
	{
		return $this->unix;
	}
/**
*	@return string the date supplied in uhu_LLSD_date::__construct()
*/
	public function __toString()
	{
		return $this->date;
	}
}
?>